//
//  OrderViewTableViewCell.m
//  Doctors
//
//  Created by 王森 on 16/4/11.
//  Copyright © 2016年 王森. All rights reserved.
//

#import "OrderViewTableViewCell.h"
#import "TMCache.h"
@implementation OrderViewTableViewCell
{
    NSString *_orderId;
    NSString *_orderStatus;
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    self.changeOrderStatus.layer.borderWidth=1;
    self.changeOrderStatus.layer.borderColor=UIColorFromRGB(0x00ccc2).CGColor;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)cellFuzhi:(OrderModel *)model
{
    NSString *orderId =StringWithFormat(model.orderId);
    _orderId=orderId;
 
    
    /*服务时间*/
    
    NSString *time_string =model.time;
    
    NSTimeInterval _interval=[time_string doubleValue] / 1000.0;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
    NSDateFormatter *objDateformat = [[NSDateFormatter alloc] init];
    [objDateformat setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
    NSString *day_date =[objDateformat stringFromDate: date];
    self.serverTime.text=day_date;
    
    self.name.text= model.username;
    self.number.text=model.mobile;
    
    self.project.text=model.project;
    // 价钱
//    NSString *price = model.price;
//    self.price.text= [NSString stringWithFormat:@"%@元/%@分钟", price,dicRecource[@"orderInfo"][@"timeLong"]];
//    
    self.price.text=[NSString stringWithFormat:@"￥%@",model.price];
    self.address.text=model.address;
    
    
    
    NSString *status =[NSString stringWithFormat:@"%d",model.orderStatus] ;
    

    if ([status isEqualToString:@"0"]) {
        self.changeOrderStatus.hidden=NO;
        self.xianImg.hidden=NO;
        [self.changeOrderStatus setTitle:@"确认处理" forState:UIControlStateNormal];
    }else if ([status isEqualToString:@"10"]){
        self.changeOrderStatus.hidden=NO;
        self.xianImg.hidden=NO;

        [self.changeOrderStatus setTitle:@"开始服务" forState:UIControlStateNormal];
    }else if ([status isEqualToString:@"20"]){
        self.changeOrderStatus.hidden=NO;
        self.xianImg.hidden=NO;
        [self.changeOrderStatus setTitle:@"服务完成" forState:UIControlStateNormal];
    }
    
    else{
        self.changeOrderStatus.hidden=YES;
        self.xianImg.hidden=YES;
        
    }
        
       
        
    

    // 观看订单状态
    
    NSString *status_order = [NSString stringWithFormat:@"%d", model.orderStatus];
    _orderStatus=status_order;
    
    if ([status_order isEqualToString:@"0"]) {
        self.status.text = [NSString stringWithFormat:@"状态：待确认"];
    }else if ([status_order isEqualToString:@"10"]){
        self.status.text = [NSString stringWithFormat:@"状态：已确认"];
    }else if ([status_order isEqualToString:@"20"]){
        self.status.text = [NSString stringWithFormat:@"状态：进行中"];
    }else if ([status_order isEqualToString:@"30"]){
        self.status.text = [NSString stringWithFormat:@"状态：服务完成"];
    }else if ([status_order isEqualToString:@"40"]){
        self.status.text = [NSString stringWithFormat:@"状态：已评价"];
    }else if ([status_order isEqualToString:@"50"]){
        self.status.text = [NSString stringWithFormat:@"状态：订单取消"];
    }else if ([status_order isEqualToString:@"60"]){
         self.status.text = [NSString stringWithFormat:@"状态：订单过期"];
    }else if ([status_order isEqualToString:@"80"]){
         self.status.text = [NSString stringWithFormat:@"状态：已退款"];
    }else if ([status_order isEqualToString:@"70"]){
        self.status.text = [NSString stringWithFormat:@"状态：退款中"];
    }else if ([status_order isEqualToString:@"90"]){
         self.status.text = [NSString stringWithFormat:@"状态：退款失败"];
    }

    
    
    
}

- (IBAction)chageOrderPress:(id)sender {
    

    NSString *status = [NSString stringWithFormat:@"%@",_orderStatus];

    if ([status isEqualToString:@"0"]) {
        status = @"10";
    }
    else if ([status isEqualToString:@"10"]){
        status = @"20";
    }
    else if ([status isEqualToString:@"20"]){
        status = @"30";
    }
    
    NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:[[TMCache sharedCache]objectForKey:@"artisanId"], @"artisanId", status, @"status", _orderId, @"orderId", nil];
    NSLog(@"改变订单状态参数：%@",dictionary);

    [self makeToastActivity:@"正在加载"];
    
    [[WSNetworkApi shareManager]postWithUrl:@"/order/setOrderStatus" parameters:dictionary option:RequestCenterCachePolicyNormal sucess:^(id responseObject) {

        
          NSLog(@"%@",responseObject);
          [self hideToastActivity];
          
          
          if ([responseObject[@"status"] isEqualToString:@"ok"]) {
           
              if (_reRqquest) {
                  _reRqquest();
                  
              }
              
          }
          else
              
          {
              [self makeToast:responseObject[@"message"]];
              
          }

      } failur:^(NSError *error) {
          NSLog(@"%@",error);
 
      }];
    
    
}

@end
